export default {
    data: function () {
        return{
            userList: []
        }
    },


    setUserTokenData(data){
        sessionStorage.setItem('user_token_data', JSON.stringify(data.data.data));
    },
    getUserTokenData(){

        if (sessionStorage.getItem("user_token_data")) {
            // 恢复文本输入框的内容
            var userJsonStr = sessionStorage.getItem("user_token_data");
            var userEntity = JSON.parse(userJsonStr);
            // console.log('user_token_data');
            // console.log(Helper.test01());
            // console.log(userEntity.data.access_token);
            // console.log(userEntity.data.token_type);

        }else{
            userEntity = {
                'access_token':'',
                'expires_in':'',
                'refresh_token':'',
                'token_type':'',

            };
        }

        // console.log(userEntity);


        // var userJsonStr = sessionStorage.getItem('user_token_data');

        return userEntity;



    },
    getUserInfo(){
        var userJsonStr = sessionStorage.getItem('user_token_data');
        var userEntity = JSON.parse(userJsonStr);
        console.log('user_token_data');
        // console.log(Helper.test01());
        console.log(userEntity.data.access_token);
        return userEntity;
    },
    axios:function(){

        var userTokenData = this.getUserTokenData();
        // console.log(userTokenData);

        var instance =axios.create({
            baseURL: '',
            timeout: 5000,
            headers: {
                Authorization:userTokenData.token_type+' '+userTokenData.access_token,
                Accept:'application/json'
            }
        });

        // var instance = axios.create();
        // instance.defaults.timeout = 2500;
        // instance.defaults.headers.common['Authorization'] = userTokenData.token_type+' '+userTokenData.access_token;
        // instance.defaults.headers.common['Accept'] = 'application/json';

        return instance;
    },
    server:function(){
        var  host= ''
        return server;
    },
    getMenus:function(){



    },
    getUsers:function () {

        // var userJsonStr = sessionStorage.getItem("user_token_data");
        // var userTokenData = JSON.parse(userJsonStr);

        this.userList = []

        var userData = jhTools.axios().get('/api/v1/users')
            .then(function (response) {
                // return response.data.data.items
                this.userList = (response.data.data.items)
            })
            .catch(function (error) {
                //vm.answer = 'Error! Could not reach the API. ' + error
                // var  userList = []
//                    console.log('fei13');
                console.log(error);

                // console.log(userList);
                // return error;

            })
        console.log("userList-start");
        console.log(this.userList);
        console.log("userList-end");

        return userList;







        var  userList = [];

            this.axios().get('http://elsf.lan6.oyfei.cn/api/v1/users')
                .then(function (response) {
                    userList = (response.data.data.items)
//                            console.log(response.data.data.items);
                    console.log('2');
                    console.log(userList);
                })
                .catch(function (error) {
                    //vm.answer = 'Error! Could not reach the API. ' + error
                   // var  userList = []

                    console.log('4');
                    console.log(error);
                })
        console.log('3');
        console.log(userList);


            return userList;
        },






}
